﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Ivy_PersonReport_GetAll')
	BEGIN
		DROP  Procedure  Ivy_PersonReport_GetAll
	END

GO

CREATE PROCEDURE [Ivy_PersonReport_GetAll]
-- =============================================
-- Author:		<Ram pravesh kr>
-- Create date: <06/06/2016>
-- Description:	<Ivy_PersonReport_GetAll>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				@Sys_IsDeleted int = 0,
				@Sys_OrganizationID int = NULL
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	SELECT   [User].[UserLoginId], 
	         [User].[UserLoginIdType], 
			 [User].[Sys_DateOfCreation],
			 [Person].[PersonKey],
			 [Person].[PersonFirstName], 
			 [Person].[PersonLastName], 
			 [Person].[PersonSex], 
			 [Person].[PersonDateOfBirth], 
             [Person].[PersonPrimaryEmailID], 
			 [Person].[PersonPrimaryEmailIsVerified], 
			 [Person].[PersonPrimaryMobileNumber], 
			 [Person].[PersonPrimaryMobileIsVerified], 
			 [Person].[PersonAddressCityName], 
             [Person].[PersonAddressStateName], 
			 [Person].[PersonAddressCountryName], 
			 [Sys_OrganizationMaster].[OrganizationName]
    FROM     [Sys_OrganizationMaster] RIGHT OUTER JOIN [Person] 
    ON       [Sys_OrganizationMaster].[OrganizationID] = [Person].[Sys_OrganizationID] RIGHT OUTER JOIN [User] 
    ON       [Person].[PersonKey] = [User].[UserPersonKey]
	WHERE		
		(
			[Person].[Sys_IsDeleted] = @Sys_IsDeleted AND
			[Person].[Sys_OrganizationID] = ISNULL( @Sys_OrganizationID, [Person].[Sys_OrganizationID] )
		);
END
GO
